//
// Created by xili on 2024/8/22 15:58.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maxSatisfied(vector<int> &customers, vector<int> &grumpy, int minutes) {
        //计算所有0的和
        int n = grumpy.size();
        int i = 0, total = 0;
        for (; i < n; i++) {
            if (!grumpy[i]) {
                total += customers[i];
            }
        }
        for (i = 0; i < minutes; i++) {
            if (grumpy[i]) {
                total += customers[i];
            }
        }
        int ans = total;
        while (i < n) {
            total += grumpy[i] ? customers[i] : 0;
            total -= grumpy[i - minutes] ? customers[i - minutes] : 0;
            i++;
            ans = max(ans, total);
        }
        return ans;
    }
};